#include"../mqserver/mq_binding.hpp"
#include<gtest/gtest.h>
mq::BindingManager::ptr bmp;

class BindingTest : public testing::Environment{
    public:
        virtual void SetUp() override{
            bmp = std::make_shared<mq::BindingManager>("./a/db_file");
        }
        virtual void TearDown() override{
            bmp->clear();
        }
};

TEST(binding_test,insert_test){
    // std::cout<<"testing"<<std::endl;
    bmp->bind("exchange1","queue1","news.music.#",true);
    bmp->bind("exchange1","queue2","news.music.#",true);
    bmp->bind("exchange2","queue2","news.sport.#",true);
    bmp->bind("exchange2","queue4","news.sport.#",true);
    bmp->bind("exchange3","queue3","news.music.#",false);
    ASSERT_EQ(bmp->size(),5);
}

// TEST(queue_test,select_test){
//     ASSERT_EQ(bmp->exists("exchange1","queue1"),true);
//     ASSERT_EQ(bmp->exists("exchange2","queue2"),true);
//     ASSERT_EQ(bmp->exists("exchange3","queue3"),true);

//     mq::Binding::ptr bind1 = bmp->getMsgQueueBinding("exchange1","queue1");
//     ASSERT_EQ(bind1->exchange_name,std::string("exchange1"));
//     ASSERT_EQ(bind1->queue_name,std::string("queue1"));
//     ASSERT_EQ(bind1->binding_key,std::string("news.music.#"));
//     ASSERT_EQ(bind1->durable,true);

//     mq::MsgQueueBindMap msgbind = bmp->getExchangeBinding("exchange1");
//     ASSERT_NE(msgbind.find("queue1"),msgbind.end());
//     ASSERT_NE(msgbind.find("queue2"),msgbind.end());

// }

// TEST(exchange_test,remove_test)
// {
//     bmp->removeMsgQueueBinding("queue1");
//     mq::MsgQueueBindMap msgbind = bmp->getExchangeBinding("exchange1");
//     ASSERT_EQ(msgbind.find("queue1"),msgbind.end());
//     ASSERT_NE(msgbind.find("queue2"),msgbind.end());

//     bmp->unBind("exchange2","queue1");
//     mq::MsgQueueBindMap msgbind2 = bmp->getExchangeBinding("exchange2");
//     ASSERT_EQ(msgbind2.find("queue1"),msgbind.end());

//     bmp->removeExchangeBinding("exchange2");
//     // ASSERT_EQ(bmp->find("exchange2"),);
//     ASSERT_EQ(bmp->getExchangeBinding("exchange2"),mq::MsgQueueBindMap());

//     ASSERT_EQ(bmp->size(),1);
// }   

int main(int argc,char* argv[]){
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new BindingTest);
    return RUN_ALL_TESTS();
}